// 修饰符
class Point {
    public x: number
    public y: number
    constructor(x: number, y: number) {
        this.x = x
        this.y = y
    }
    public getP() {
        return `(${this.x},${this.y})`
    }
}

const point = new Point(1, 2);

class Parent {
    public name: string
    constructor(name: string) {
        this.name = name
    }
}
class Child extends Parent {
    constructor(name: string) {
        super(name)
    }
}

// 修饰符  public static
// pubic 公共的，外部可以访问的实例和方法

// protected 受保护
class C {
    // protected 保护的值不能被访问
    protected age: number
    // 被保护的constructor不能创建实例对象
    protected constructor(age: number) {
        this.age = age
    }
    // 函数可以被访问
    protected getC() {
        return this.age
    }
}
const D = new C(0)

class ChildC extends C {
    constructor(age: number) {
        super(age)
        super.age;
        super.getC()
    }
}
const M = new ChildC(10)

// private 私有的

class B {
    private age: number
    constructor(age: number) {
        this.age = age
    }
}
// readonly  只读属性

class UserInfo {
    public readonly name: string
    constructor(name: string) {
        this.name = name
    }
}
const user = new UserInfo('aaaa')


// 访问限定符
class A {
    constructor(public name: string) {
    }
}

const a = new A('aaa')

// 静态属性 static

class ParentA {
    private static age: number = 18
    public static getAge() {
        return ParentA.age
    }
    constructor() { }
}

const p = new ParentA()
// p.age;
// ParentA.age;

// 可选类属性 

class info {
    public name: string
    public age?: number
    private _infoStr: string
    constructor(name: string, age?: number, public sex?: string) {
        this.name = name;
        this.age = age;
    }
    get infoStr() {
        return `${this.name}:${this.age}`
    }
    set infoStr(value) {
        console.log(`setter:${value}`)
        this._infoStr = value;
    }
}

const info1 = new info('dh')
const info2 = new info('dh', 18)
const info3 = new info('dh', 18, 'man')

// 抽象类 被其他类继承 

abstract class People {
    constructor(public name: string) { }
    public abstract printName(): void
}

class Man extends People {
    constructor(name: string) {
        super(name)
        this.name = name
    }
    // 非抽象类不会继承抽象类的方法
    printName() {
        console.log()
    }
}

const dh = new Man('dh')

dh.printName()

abstract class People2 {
    abstract _name: string
    abstract get insideName(): string
    // 存值器不能设定返回值类型
    abstract set insideName(value: string)
}

class O extends People2 {
    // 非抽象类“O”不会实现继承自“People2”类的抽象成员“insideName”
    public _name: string
    public insideName: string
    constructor() {
        super()
    }
}

interface FoodInterface {
    type: string
}

// 使用接口时

class FoodClass implements FoodInterface {
    public type: string
    constructor(type: string) {
        this.type = type
    }
}

// 接口继承类